package com.thefirststage.module4;

/*
编写一个员工类

      属性: 姓名,年龄

      如果年龄小于18龄大于150抛出年龄异常

      如果姓名为null或者""抛出空异常
      作者：翁海龙
 */
public class Worker {
    private String name;
    private int age;

    public Worker() {
    }

    public Worker(String name, int age) throws AgeException {
        setName(name);
        setAge(age);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(null == name ||"".equals(name){
            throw new NullPointerException();
        }else{

            this.name=name;
        }

    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
        if(age<18 || age>150){
            throw new AgeException("年龄不合理！");
        }else{

            this.age = age;
        }
    }



    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
